home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / quodlibet / qltk / menubutton.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  3KB  |  76 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. from gi.repository import Gtk, Gdk
  5. from quodlibet import qltk
  6.  
  7. class MenuButton(Gtk.ToggleButton):
  8.     __menu = None
  9.     __menu_sig = None
  10.     
  11.     def __init__(self, widget = None, arrow = False, down = True):
  12.         super(MenuButton, self).__init__()
  13.         bbox = Gtk.HBox(spacing = 3)
  14.         if widget:
  15.             bbox.pack_start(widget, True, True, 0)
  16.         if arrow:
  17.             arrow_type = Gtk.ArrowType.DOWN if down else Gtk.ArrowType.UP
  18.             bbox.pack_start(Gtk.Arrow.new(arrow_type, Gtk.ShadowType.IN), True, True, 0)
  19.         self._down = down
  20.         self.add(bbox)
  21.         self.connect('toggled', self._MenuButton__toggled_cb)
  22.         self.connect('button-press-event', self._MenuButton__press_cb)
  23.         self.connect('destroy', self._MenuButton__destroy)
  24.  
  25.     
  26.     def get_menu(self):
  27.         return self._MenuButton__menu
  28.  
  29.     
  30.     def set_menu(self, menu):
  31.         if self._MenuButton__menu:
  32.             self._MenuButton__menu.detach()
  33.             self._MenuButton__menu.disconnect(self._MenuButton__menu_sig)
  34.         self._MenuButton__menu = menu
  35.         menu.attach_to_widget(self, None)
  36.         self._MenuButton__menu_sig = menu.connect('deactivate', self._MenuButton__menu_deactivate_cb, self)
  37.  
  38.     
  39.     def __destroy(self, *args):
  40.         if self._MenuButton__menu:
  41.             self._MenuButton__menu.detach()
  42.             self._MenuButton__menu.disconnect(self._MenuButton__menu_sig)
  43.         self._MenuButton__menu = None
  44.  
  45.     
  46.     def __menu_deactivate_cb(self, menu, button):
  47.         button.set_active(False)
  48.  
  49.     
  50.     def __press_cb(self, widget, event):
  51.         if self._MenuButton__menu and event.button == Gdk.BUTTON_PRIMARY:
  52.             widget.set_active(True)
  53.             return True
  54.  
  55.     
  56.     def _popup(self):
  57.         event = Gtk.get_current_event()
  58.         (ok, button) = event.get_button()
  59.         if not ok:
  60.             button = Gdk.BUTTON_PRIMARY
  61.         time = event.get_time()
  62.         if self._down:
  63.             qltk.popup_menu_under_widget(self._MenuButton__menu, self, button, time)
  64.         else:
  65.             qltk.popup_menu_above_widget(self._MenuButton__menu, self, button, time)
  66.  
  67.     
  68.     def __toggled_cb(self, widget):
  69.         menu = self._MenuButton__menu
  70.         if widget.get_active() and menu:
  71.             self._popup()
  72.         elif menu:
  73.             menu.popdown()
  74.  
  75.  
  76.